<?php

namespace App\Repositories\Eloquent;

use App\Models\CabinSet;
use App\Repositories\Contracts\CabinSetInterface;
use MakeRep\Repository;

class CabinSetRepository extends Repository implements CabinSetInterface
{

    function model()
    {
        return CabinSet::class;
    }

    /**
     * 添加座位设置
     * @param $data
     * @return void
     */
    public function create($data,$policyId){

        if (isset($data['stock'])) {

            $this->delete(['policy_id'=>$policyId]);

            $stock = [];
            $time = date('Y-m-d H:i:s');
            foreach ($data['stock'] as $key=>$value) {

                $item = [
                    'policy_id'=>$policyId,
                    'stock' => $value,
                    'cabin_min' => $data['cabin_min'][$key],
                    'cabin_max' => $data['cabin_max'][$key],
                    'created_at' => $time,
                    'updated_at' => $time,
                ];

                $stock[] = $item;
            }

            if ($stock) {

                $this->insert($stock);
            }
        }

    }

    public function update($where, $data)
    {

        return parent::update($where, $data); // TODO: Change the autogenerated stub
    }
}